package com.czk.netty.zerocopy.practice;

import java.io.FileInputStream;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.channels.FileChannel;
import java.nio.channels.SocketChannel;

/**
 * 网络传输文件客户端
 *
 * @Author:ChenZhangKun
 * @Date: 2021/4/9 10:21
 */
public class TransferFileClient {
    public static void main(String[] args) throws IOException {
        // 配置主机
        SocketChannel socketChannel = SocketChannel.open();
        // 监听端口
        socketChannel.connect(new InetSocketAddress("localhost", 8080));
        // 配置非阻塞
        //socketChannel.configureBlocking(false);
        // 设置文件输入流
        FileInputStream fileInputStream = new FileInputStream("d:\\简历\\x.txt");
        // 拿到通道
        FileChannel channel = fileInputStream.getChannel();

        // 发送
        channel.transferTo(0, channel.size(), socketChannel);
        System.in.read();
    }
}
